package com.example.demo.controller;

import com.example.demo.dao.commodity;
import com.example.demo.dao.order;
import com.example.demo.service.commodityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin(origins = "*")
@RestController
public class commodityController {
    @Autowired
    private commodityService commodityService;
    @PostMapping("/commodity")//根据商品名查询商品
    public List<commodity> getCommodityByName(@RequestBody commodity commodity){
        return commodityService.getCommodityByCommodityName(commodity.getCommodityName());
    }
    @PostMapping("/getCommodityByUserName")//根据用户名查询商品列表
    public List<commodity> getCommodityByUserName(@RequestBody commodity commodity){
        return commodityService.getCommodityByUserName(commodity.getUserName());
    }
    @GetMapping("/index")//查询所有商品
    public List<commodity> getAllCommodity(){
        return commodityService.getCommodityAll();
    }
    @PostMapping("/getCommodityById")//根据id查询商品
    public commodity getCommodityById(@RequestBody commodity commodity){
        return commodityService.getCommodityById(commodity.getCommodityId());
    }
    @PostMapping("/addCommodity")//增加商品
    public commodity addCommodity(@RequestBody commodity commodity){
        return commodityService.addCommodity(commodity);
    }
    @PostMapping("/updCommoditySold")
    public commodity updCommoditySold(@RequestBody commodity commodity){
        return  commodityService.updateCommoditySold(commodity.getCommodityId(),commodity.getCommodityOnSale(),commodity.getCommoditySold());
    }
    @PostMapping("/delCommodityById")
    public void delcommodityById(@RequestBody commodity commodity){
        commodityService.delcommodityById(commodity.getCommodityId());
    }
}
